package com.bee.bootstrap;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableSwagger2
@ComponentScan(basePackages = {"com.bee.bootstrap.*.controller"})
public class Swagger2 {

    @Bean
    public Docket createRestApi() {
        ParameterBuilder authorizationPar = new ParameterBuilder();
        ParameterBuilder clientPar = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<Parameter>();
        authorizationPar.name("Authorization").description("授权Authorization Token")
                .modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build();
        clientPar.name("client").description("请求来源")
                .modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build();
        pars.add(authorizationPar.build());
        pars.add(clientPar.build());
        return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .build()
                .globalOperationParameters(pars)
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Bee Restful Apis")
                .description("火炬项目Api")
                .contact("创屎人")
                .version("1.0")
                .build();
    }



}
